package com.jiantong.web.core.enums;

/**
 * Created by mz on 5/7/17.
 *
 */
public enum  ExceptionCode {

    ID_NOT_EXIST(10000,"主键ID不存在"),
    PARAMETER_NOT_EXIST(10002,"参数不存在"),
    DOCUMENT_REPEAT_SUBMIT(10001,"单据重复提交"),
    OBJECT_NOT_EXIST(10002,"对象不存在"),
    PARAMETER_IS_INVALID(10003,"参数无效"),
    DATA_NOT_FOUND(20000,"数据没找到"),
    DATA_WRITE_FAIL(20001,"数据写入错误"),
    DATA_UPDATE_FAIL(20002,"数据更新错误"),
    DATA_DELETE_FAIL(20003,"数据删除失败");


    private final Integer value;
    private final String description;

    ExceptionCode(Integer value, String description){
        this.value = value;
        this.description = description;
    }

    public static ExceptionCode from(Integer value) {
        for (ExceptionCode exceptionCode : ExceptionCode.values()) {
            if (exceptionCode.value.equals(value)) {
                return exceptionCode;
            }
        }
        return null;
    }

    public Integer value() {
        return this.value;
    }

    @Override
    public String toString() {
        return description;
    }
}
